package edu.pku.sei.act.ctrl.command;

import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.CompoundCommand;

import edu.pku.sei.act.model.common.ArchiModel;

import edu.pku.sei.act.model.mote.AcceptAction;
import edu.pku.sei.act.model.mote.Action;
import edu.pku.sei.act.model.mote.ActivityFinal;
import edu.pku.sei.act.model.mote.Data;
import edu.pku.sei.act.model.mote.DecisionNode;
import edu.pku.sei.act.model.mote.InitialNode;
import edu.pku.sei.act.model.mote.MergeNode;
import edu.pku.sei.act.model.mote.Mote;
import edu.pku.sei.act.model.mote.MoteForPackage;
import edu.pku.sei.act.model.mote.PackageI;
import edu.pku.sei.act.model.mote.Radio;
import edu.pku.sei.act.model.mote.LIP;
import edu.pku.sei.act.model.mote.SendAction;
import edu.pku.sei.act.model.mote.SimpleDevice;
import edu.pku.sei.act.model.mote.TaskEditArea;
import edu.pku.sei.act.model.mote.Timer;
import edu.pku.sei.act.model.mote.Task;
import edu.pku.sei.gmp.controller.command.GMPCommandFactory;
import edu.pku.sei.gmp.controller.command.GMPCreateRelationCommand;
import edu.pku.sei.gmp.model.concept.GMPModelElement;

public class ArchiModelerCommandFactory extends GMPCommandFactory{

	
	private static ArchiModelerCommandFactory instance;

	public static ArchiModelerCommandFactory getInstance() {
		if (instance == null) {
			instance = new ArchiModelerCommandFactory();
		}
		return instance;
	}
	@Override
	protected boolean buildCompleteRelationCommand(
			GMPCreateRelationCommand cmd, GMPModelElement targetModel) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	protected Command buildCreateModelElementCommand(GMPModelElement parent,
			GMPModelElement modelElement) {
		if (parent instanceof ArchiModel) {
			if (modelElement instanceof Mote) {
				return new CreateMoteCommand((ArchiModel) parent, (Mote) modelElement);
			}else if(modelElement instanceof PackageI){
				return new CreatePackageCommand((ArchiModel) parent, (PackageI) modelElement);
			}else if(modelElement instanceof TaskEditArea){
				return new CreateTaskEditAreaCommand((ArchiModel)parent, (TaskEditArea)modelElement);
			}
		}else if (parent instanceof Mote){
			if(modelElement instanceof Data){
				return new CreateDataCommand((Mote) parent, (Data) modelElement);
			}else if(modelElement instanceof Radio){
				return new CreateRadioCommand((Mote) parent, (Radio) modelElement);
			}else if(modelElement instanceof LIP){
				return new  CreateLIPCommand((Mote)parent,(LIP)modelElement);
			}else if(modelElement instanceof Timer){
				return new CreateTimerCommand((Mote)parent,(Timer)modelElement);
			}else if(modelElement instanceof SimpleDevice){
				return new CreateSimpleDeviceCommand((Mote)parent,(SimpleDevice)modelElement);
			}else if(modelElement instanceof Task){
				return new CreateTaskCommand((Mote)parent, (Task)modelElement);
			}
		}else if (parent instanceof PackageI){
			if(modelElement instanceof MoteForPackage){
				return new CreateMoteForPackageCommand((PackageI) parent, (MoteForPackage) modelElement);
			}
		}else if(parent instanceof TaskEditArea){
			if(modelElement instanceof Action){
				return new CreateActionCommand((TaskEditArea)parent, (Action)modelElement);
			}else if(modelElement instanceof InitialNode){
				return new CreateActionCommand((TaskEditArea)parent, (InitialNode)modelElement);
			}else if(modelElement instanceof SendAction){
				return new CreateSendActionCommand((TaskEditArea)parent, (SendAction)modelElement);
			}else if(modelElement instanceof AcceptAction){
				return new CreateAcceptActionCommand((TaskEditArea)parent, (AcceptAction)modelElement);
			}else if(modelElement instanceof DecisionNode){
				return new CreateDecisionNodeCommand((TaskEditArea)parent, (DecisionNode)modelElement);
			}else if(modelElement instanceof MergeNode){
				return new CreateMergeNodeCommand((TaskEditArea)parent, (MergeNode)modelElement);
			}else if(modelElement instanceof ActivityFinal){
				return new CreateActivityFinalCommand((TaskEditArea)parent, (ActivityFinal)modelElement);
			}
		}
		return null;	 
	}

	@Override
	protected void buildDeleteSubModelElementCommand(CompoundCommand cmd,
			GMPModelElement modelElement) {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected Command getCreateRelationCommand(GMPModelElement sourceModel,
			GMPModelElement linkModel) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected Command getDeleteDirectModelElementCommand(
			GMPModelElement modelElement) {
		if(modelElement instanceof Mote){
			return new DeleteMoteCommand((Mote) modelElement);
		}
		return null;
	}

}
